import { connect } from 'react-redux';
import { toggleTodoAction, delTodoAction } from '../../redux/actions';
// 导入展示组件
import TodoList from '../../pages/TodoList';




// 连接到store，获取state共享数据
/**
 * 
 * @param {*} state store里定义的state数据
 * @param {*} ownProps 组件自身的props
 */
const mapStateToProps = (state, ownProps) => {
  // console.log('fn:', state, ownProps)
  return {
    list: state
  }
}

//  获取修改store数据的方法
const mapDispatchToProps = (dispatch) => {

  return {
    // 切换任务状态：done
    toggle(id) {
      dispatch(toggleTodoAction(id))
    },
    // 删除任务
    del(id) {
      dispatch(delTodoAction(id))
    }
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(TodoList);